package com.hdu.degrete;


import com.hdu.degrete.degrate.Degrate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

import static com.hdu.degrete.degrate.CircuitBreaker.DegrateType.CUSTOM_RESULT;


@RestController
public class TestController {


    @GetMapping("test/{num}")
    @Degrate(
            degrateTime = 50,
            timeUnit = TimeUnit.SECONDS,
            degrateType = CUSTOM_RESULT,
            failRate = 0.5,
            customResultHandler = MyCustomResultHandler.class,
            methodName = "returnCustomResult"
    )
    public String test(@PathVariable int num) {
        if (num == 0) {
            throw new RuntimeException();
        } else {
            return "success";
        }
    }
}
